import json
import random
from flask import Flask, request
from flask_cors import CORS



app = Flask(__name__)
cors = CORS(app, supports_credentials=True,
            resources={r"/getAllData": {"origins": "*"}})

@app.route('/getAllData', methods=['GET', 'POST'])
def get_all_data():
    val = request.get_json()
    print(val)
    with open("./Ti_data/graph_data_raw.json",'r',encoding="utf8") as file:
        graph_data_raw=json.load(file)
    with open("./Ti_data/graph_data_raw_new.json",'r',encoding="utf8") as file:
        graph_data_raw_new=json.load(file)
    with open("./Ti_data/graph_data_matrix.json",'r',encoding="utf8") as file:
        graph_data_matrix=json.load(file)
    with open("./Ti_data/graph_data_matrix_new.json",'r',encoding="utf8") as file:
        graph_data_matrix_new=json.load(file)
    if val["first"]:
        if val["view"]=="Raw View":
            data=graph_data_raw
            print(1)
        else:
            data=graph_data_matrix
            print(2)
    else:
        if val["view"]=="Raw View":
            data=graph_data_raw_new
            print(3)
        else:
            data=graph_data_matrix_new
            print(4)
    return {
        "data":data
    }

if __name__ == '__main__':
    app.run(debug=True)


